/*
 * Copyright 2021-2030 itbox.cn All right reserved. This software is the confidential and proprietary information
 * of itbox.cn ("Confidential Information"). You shall not disclose such Confidential Information and shall use it
 * only in accordance with the terms of the license agreement you entered into with itbox.cn.
 */
package cn.itbox.example.domain.model;

import cn.itbox.uap.domain.model.BaseModel;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @BelongProject springboot-study
 * @BelongPackage cn.itbox.example.domain.model
 * @Description TODO
 * @ClassName User
 * @Author xingc
 * @Date 2023/11/26 21:07
 * @Version 1.0.0
 */
@Setter
@Getter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@ToString
public class UserModel extends BaseModel {
    /**
     * 用户名
     */
    private String userName;

    /**
     * 真是姓名
     */
    private String realName;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 密码
     */
    private String password;


    /**
     * 用户地址
     */
    private AddressModel address;

    /**
     * 用户单位
     */
    private UnitModel unit;

    /**
     * 角色
     */
    @Singular(value = "addRole")
    private List<RoleModel> roles;

    public void bindRoleByRoleId(List<Long> roleIds){
        this.roles = roleIds.stream()
                .map(roleId-> RoleModel.builder().id(roleId).build())
                .collect(Collectors.toList());
    }

    public void bindAddress(String province,String city,String county){
        this.address = new AddressModel(province,city,county);
    }

    public void bindUnit(Long unitId,String unitName){
        this.unit = new UnitModel(unitId,unitName);
    }

}
